<style>
.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
.order-time-bg{background-color:#1E9FFF;color:white;padding:0px 5px;}
.order-num span{display:inline-block;min-width:25px;margin:0px 2px;text-align:center;}
.layui-table-cell{line-height:23px;padding:4px 6px;}
</style>
<div class="fixed-bar">
<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
<div class="layui-form-item">	
	<div class="layui-inline">
    	<a href="{:url('StockEdit')}?action=addstock" title="新增库存盘点" hisi-data="{width: '500px', height: '500px'}" style="display:none;" class="hisi-iframe layui-btn layui-btn-danger layui-btn-sm">库存盘点</a>
        <a href="{:url('StockEdit')}?action=scan_code" title="库存盘点" hisi-data="{width: '800px', height: '500px'}" style="display:none" class="hisi-iframe layui-btn layui-btn-danger layui-btn-sm tail-defective">库存盘点</a>
        
    </div>
	<div class="layui-inline">
		<label class="layui-form-label">SKU</label>
		<div class="layui-input-inline">
			<input type="text" name="sku" lay-verify="" placeholder="输入SKU" class="layui-input">
		</div>
	</div>
    <div class="layui-inline">
		<label class="layui-form-label">订单号</label>
		<div class="layui-input-inline">
			<input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
		</div>
	</div>
	<div class="layui-inline">
		<label class="layui-form-label">所属工厂</label>
		<div class="layui-input-inline">
			{:Form::select('factory_id', '', $factoryKV, '', '')}
		</div>
	</div>
	<div class="layui-inline">
		<label class="layui-form-label">最后更新</label>
		<div class="layui-input-inline time_input">
			<input type="text" name="over_time_range" readonly="" id="over_time_range" lay-verify="" placeholder="更新截止日期" class="layui-input">
		</div>
	</div>
	<div class="layui-inline">
		<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
    <button type="button" class="layui-btn layui-btn-primary hisi-export">导出</button>
	</div>
</div>
</form>
</div>
<table id="dataTable"></table>
{include file="system@block/layui" /}
<script type="text/html" id="toolbar">
	<span id="totaldata_tag">sku:个，正品：件，次品：件  总价格：元</span>
	&nbsp; <a href="{:url('skuStockLog')}" title="成衣库存明细报表" class="hisi-iframe layui-btn layui-btn-danger layui-btn-sm tail-defective" hisi-data="{width: '100%', height: '100%'}">明细报表</a>
</script>
<script type="text/html" id="factocyTpl">
	{{# for(var i in d.factory_stock){ }}
    	{{ d.factory_stock[i].factory }}<br />
	{{# } }}
</script>
<script type="text/html" id="size_stock">
	{{# for(var i in d.factory_stock){ }}
		{{# if(d.factory_stock[i].size_count>0){ }}
			<span>{{d.factory_stock[i].size_name }}</span>：{{d.factory_stock[i].size_count }}<br />
		{{# } }}	
	{{# } }}
	<b>总：</b>{{d.all_stock}}
</script>
<script type="text/html" id="defective_count">
	{{# for(var i in d.factory_stock){ }}
		{{# if(d.factory_stock[i].defective_size_count>0){ }}
    	<span>{{d.factory_stock[i].size_name }}</span>：{{d.factory_stock[i].defective_size_count }}<br />
		{{# }}}
	{{# } }}
</script>

<script type="text/html" id="defective_reasonTpl">
	{{# for(var i in d.factory_stock){ }}
    	{{ d.factory_stock[i].defective_reason }}<br />
	{{# } }}
</script>
<script type="text/html" id="client_ordernum">
	{{# for(var i in d.factory_stock){ }}
    	<span class="copy-item">{{ d.factory_stock[i].client_ordernum }}</span><br />
	{{# } }}
</script>
<script type="text/html" id="stock_positionTpl">
	{{# for(var i in d.factory_stock){ }}
    	{{ d.factory_stock[i].stock_position }}<br />
	{{# } }}
</script>
<script type="text/html" id="buttonTpl">
	<div style="line-height:35px">
		<a href="{:url('StockEdit')}?sku={{ d.sku }}" title="盘点编辑库存" hisi-data="{width: '760px', height: '500px'}" class="hisi-iframe layui-btn layui-btn-danger layui-btn-sm tail-defective">盘点编辑</a><br />
		<a href="{:url('skuStockLog')}?showtype=only_one_sku&sku={{ d.sku }}" title="出入库详情" class="hisi-iframe layui-btn layui-btn-sm layui-btn-normal" target="_blank"  hisi-data="{width: '70%', height: '70%'}">出入库详情</a>
	</div>
</script>

<script type="text/javascript">
    layui.use(['table','opTable', 'tool', 'jquery', 'laydate', 'form'], function() {
        var $ = layui.jquery;
        var laydate = layui.laydate;
        var form = layui.form;
        var table = layui.table;
        
        laydate.render({
		    elem: '#over_time_range'
		    ,change: function(value, date, endDate){
		    	$('#over_time_range').val(value);
            }
		});
        
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,cellMinWidth: 80
			,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
            	{field: 'pic', title:'图片',templet:function(d){return '<span class="lay-pic-container" src="'+ d.pic +'"><img src="'+ d.pic +'" class="lay-pic"></span>'},width:120}
            	,{field: 'sku', title:'SKU',width:210,templet:function(d){ return'<span class="copy-item">'+d.sku+'</span><br>'+d.factory_stock[0].account;}}
            	,{field: 'available_count', title:'正品',templet:'#size_stock'}
            	,{field: 'defective_count', title:'次品',templet:'#defective_count'}
            	,{field: 'defective_reason', title:'订单号',templet: '#client_ordernum'}
            	,{field: 'factory_id', title:'所属工厂',templet: '#factocyTpl'}
            	,{field: 'true_weight', title:'货架号',templet: '#stock_positionTpl'}
            	,{field: 'price', title:'FOB价'}
            	,{field: 'price', title:'正品库存价值',templet: function(d){var money_total=d.price*d.available_count;return money_total.toFixed(2);}}
				,{field: 'defective_reason', title:'次品原因',templet: '#defective_reasonTpl'}
            	,{field: 'update_time', title:'最后更新日期',width:160,templet: function(d){return layui.util.toDateString(d.update_time*1000,'yyyy-MM-dd HH:mm')}}
                ,{title: '操作', templet: '#buttonTpl', width:120, fixed: 'right'}
            ]]
            ,done:function(res) {
				var totaldata=res.totaldata;
				$("#totaldata_tag").html('sku：<strong>'+res.count+'</strong>个，正品：<strong>'+totaldata.available_count+'</strong>件，  正品总价值：<strong>'+totaldata.total_price+'</strong>元， 次品：<strong>'+totaldata.defective_count+'</strong>件，次品总价值：<strong>'+totaldata.defective_total_price+'</strong>元 ');
            }
        });
    });
</script>